import { createApp } from 'vue'
import App from './App.vue'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import router from './router/index.js'
import axios from './axiosInstance.js'
import { createPinia } from "pinia"
import piniaPluginPersist from 'pinia-plugin-persistedstate'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import { config, library } from '@fortawesome/fontawesome-svg-core'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import { fas } from '@fortawesome/free-solid-svg-icons'


// 禁用自动添加 CSS
config.autoAddCss = false

// 添加 solid 风格的所有图标
library.add(fas)

const app = createApp(App)
const pinia = createPinia()

// 注册 Element Plus 图标
for (const [name, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(name, component)
}

// 全局注册 Font Awesome 组件
app.component('font-awesome-icon', FontAwesomeIcon)

// 使用插件
app.use(ElementPlus, { locale: zhCn })
app.use(router)
app.use(pinia)
pinia.use(piniaPluginPersist)  // 修正了这行的使用方式

// 全局挂载 axios
app.config.globalProperties.$axios = axios

app.mount('#app')